<?php
require "secretiki.php";
?>

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="author" content="Roman Shangin">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=0, minimal-ui">
    <title>Асик - сервисный центр</title>
    <!-- Fevicon -->
    <link rel="shortcut icon" href="assets/images/favicon.ico">
    <!-- Start css -->
    <!-- Switchery css -->
    <link href="index/assets/plugins/switchery/switchery.min.css" rel="stylesheet">
    <!-- Apex css -->
    <link href="index/assets/plugins/apexcharts/apexcharts.css" rel="stylesheet">
    <!-- Slick css -->
    <link href="index/assets/plugins/slick/slick.css" rel="stylesheet">
    <link href="index/assets/plugins/slick/slick-theme.css" rel="stylesheet">
    <link href="index/assets/css/bootstrap.min.css" rel="stylesheet" type="text/css">
    <link href="index/assets/css/icons.css" rel="stylesheet" type="text/css">
    <link href="index/assets/css/flag-icon.min.css" rel="stylesheet" type="text/css">
    <link href="index/assets/css/style.css" rel="stylesheet" type="text/css">
    <!-- End css -->
</head>

<?php
include "body-head.php";
?>

            <!-- Start Contentbar -->    
            <div class="contentbar">                
                <!-- Start row -->
                <div class="row">
                    <!-- Start col -->
                    <div class="col-lg-5 col-xl-3">
                        <div class="card m-b-30">
                            <div class="card-body">
                                <div class="nav flex-column nav-pills" id="v-pills-tab" role="tablist" aria-orientation="vertical">
                                    <a class="nav-link mb-2 active" id="v-pills-profile-tab" data-toggle="pill" href="#v-pills-profile" role="tab" aria-controls="v-pills-profile" aria-selected="true"><i class="feather icon-user mr-2"></i>Аккаунт</a>
                                    <a class="nav-link mb-2" id="v-pills-order-tab" data-toggle="pill" href="#v-pills-order" role="tab" aria-controls="v-pills-order" aria-selected="false"><i class="feather icon-package mr-2"></i>Услуги</a>
                                    <a class="nav-link mb-2" id="v-pills-wishlist-tab" data-toggle="pill" href="#v-pills-wishlist" role="tab" aria-controls="v-pills-wishlist" aria-selected="false"><i class="feather icon-heart mr-2"></i>Заказы</a>
                                    <a class="nav-link" id="v-pills-logout-tab" data-toggle="pill" href="#v-pills-logout" role="tab" aria-controls="v-pills-logout" aria-selected="false"><i class="feather icon-log-out mr-2"></i>Выход</a>
                                </div>
                            </div>
                        </div>
                    </div>
                    <!-- End col -->
                    <!-- Start col -->
                    <div class="col-lg-7 col-xl-9">
                        <div class="tab-content" id="v-pills-tabContent">
                    <!-- My Profile Start -->
                            <div class="tab-pane fade show active" id="v-pills-profile" role="tabpanel" aria-labelledby="v-pills-profile-tab">
                                <div class="card m-b-30">
                                    
<style>
      .wrapper {
        width: 300px;
        height: 300px;
        border-radius: 50%; /* Радиус скругления */
      }
      .exmp2 {
        background-image: url(/images/braineater.png);
        background-repeat: no-repeat;
        background-position: -40px 0px;
        background-size: cover;
      }

</style>                               
                                    <div class="card-body">
                                        <div class="profilebox pt-4 text-center">
                                            <ul class="list-inline">
                                                <li class="list-inline-item">
                                                    <a data-toggle='modal' data-target='#exampleModal' class="btn btn-success-rgba font-18"><i class="feather icon-edit"></i></a>
                                                </li>
                                                <li class="list-inline-item">
                                                    <img src="<?php echo "assets/images/$obje->avatar_user"; ?>" class="wrapper exmpl2 img-fluid" alt="profile">
                                                </li>
                                                <li class="list-inline-item">
                                                    <a href="del_ava" name="del" class="btn btn-danger-rgba font-18"><i class="feather icon-trash"></i></a>
                                                </li>
                                            </ul>
                                        </div>
                                    </div>
                                </div>
                                

  
    <!-- Modal -->
    <div class="modal fade" id="exampleModal" tabindex="-1" aria-labelledby="exampleModalLabel" aria-hidden="true">
      <div class="modal-dialog">
        <div class="modal-content">
          <div class="modal-header">
            <h5 class="modal-title" id="exampleModalLabel">
                <div class='nametitle'>
                <p></p>
                </div>
            </h5>
            <button type="button" class="close" data-dismiss="modal" aria-label="Close">
              <span aria-hidden="true">&times;</span>
            </button>
          </div>
          <div class="modal-body">
            <div class="row">
            </div>
            <form action = 'obr2' method = 'post' enctype = "multipart/form-data">
            <div class="contentbar">
                <!-- Start row -->
                <div class="row">
                    <!-- Start col -->
                    <div class="col-md-12 col-lg-12 col-xl-12">
                        <div class="card m-b-30">
                            <div class="card-body">
                                    <div class="fallback">
                                        <input name="ava" type="file" multiple="multiple">
                                    </div>
                            </div>
                        </div>                        
                    </div>
                    <!-- End col -->
                </div> 
                <!-- End row -->
            </div>
              <input id="hide1" type="hidden" name="id_hui" value="">
              <input id="hide2" type="hidden" name="id_pizda" value="">
              <button type="submit" class="btn btn-success w-100">Загрузить</button>
              </form> 
          </div>
        </div>
      </div>
    </div>                                
                                
                                
                                
                                
                                
                                
                                
                                
                                <div class="card m-b-30">
                                    <div class="card-body">
                                        <form action="account.php" method="post">
                                            <div class="form-row">
                                                <div class="form-group col-md-6">
                                                    <label for="username">Имя</label>
                                                    <input type="text" value="<?php echo "$obje->name"; ?>" class="form-control" id="username" readonly>
                                                </div>
												<div class="form-group col-md-6">
                                                    <label for="username">Фамилия</label>
                                                    <input type="text" value="<?php echo "$obje->family"; ?>" class="form-control" id="username" readonly>
                                                </div>
                                            </div>
                                            <hr>
                                            
                                            
                                            
<script src="assets/js/vendor/jquery-1.12.4.min.js"></script>
<script type="text/javascript" src="assets/Inputmask-5.x/dist/jquery.inputmask.js"></script>                                         
                                        
 <script>
$(document).ready(function () {
    $("#phone").inputmask({"mask": "+7 (999) 999-99-99"});
    $("#phone2").inputmask({"mask": "+7 (999) 999-99-99"});
});
</script>                                             
                                            
                                            
                                            
                                            <div class="form-row">
                                                <div class="form-group col-md-6">
                                                    <label for="usermobile">Номер телефона</label>
                                                    <input type="text" name="telephone" value="<?php echo "$obje->telephone"; ?>" class="form-control" id="phone">
                                                </div>
                                                <div class="form-group col-md-6">
                                                    <label for="useremail">Email</label>
                                                    <input type="email" name="email" value="<?php echo "$obje->email"; ?>" class="form-control" id="useremail">
                                                </div>
                                                <div class="form-group col-md-6">
                                                    <label for="userpassword">Пароль</label>
                                                    <input type="password" name="password" class="form-control" id="userpassword">
                                                </div>
                                                <div class="form-group col-md-6">
                                                    <label for="userconfirmedpassword">Подтвердить пароль</label>
                                                    <input type="password" name="password_2" class="form-control" id="userconfirmedpassword">
                                                </div>
                                            </div>
                                            <button type="submit" name="do_pizdec" class="btn btn-primary-rgba font-16"><i class="feather icon-save mr-2"></i>Сохранить</button>
                                        </form>
                                    </div>
                                    
<?php 
// Создаем переменную для сбора данных от пользователя по методу POST
$data = $_POST;

// Пользователь нажимает на кнопку "Зарегистрировать" и код начинает выполняться
if(isset($data['do_pizdec'])) {

        // Регистрируем
        // Создаем массив для сбора ошибок
	$errors = array();

	// Проводим проверки
        // trim — удаляет пробелы (или другие символы) из начала и конца строки

         // функция mb_strlen - получает длину строки

    if($data['password'] != '') {
         
    if($data['password_2'] != $data['password']) {

		$errors[] = "Повторный пароль введен не верно!";
	}     
         

    if (mb_strlen($data['password']) < 2 || mb_strlen($data['password']) > 20){
	
	    $errors[] = "Недопустимая длина пароля (от 2 до 20 символов)";

    }

    // проверка на правильность написания Email
    if (!preg_match("/[0-9a-z_]+@[0-9a-z_^\.]+\.[a-z]{2,3}/i", $data['email'])) {

	    $errors[] = 'Неверно введен е-mail';
    
    } 

    if($data['telephone'] != $pohon) {

	// Проверка на уникальность логина
	if(R::count('users', "telephone = ?", array($data['telephone'])) > 0) {

		$errors[] = "Пользователь с таким номером телефона существует!";
	}
    }



        if($data['email'] != $emuil) {

	// Проверка на уникальность email

	if(R::count('users', "email = ?", array($data['email'])) > 0) {

		$errors[] = "Пользователь с таким Email существует!";
	}
        }


	if(empty($errors)) {


        $id = $polzovatel;
        $user = R::load('users', $id);
                // добавляем в таблицу записи
		$user->telephone = $data['telephone'];
		$user->email = $data['email'];
		// Хешируем пароль
		$user->password = password_hash($data['password'], PASSWORD_DEFAULT);

		// Сохраняем таблицу
		R::store($user);
	}

    
}

    // проверка на правильность написания Email
    if (!preg_match("/[0-9a-z_]+@[0-9a-z_^\.]+\.[a-z]{2,3}/i", $data['email'])) {

	    $errors[] = 'Неверно введен е-mail';
    
    } 

    if($data['telephone'] != $pohon) {

	// Проверка на уникальность логина
	if(R::count('users', "telephone = ?", array($data['telephone'])) > 0) {

		$errors[] = "Пользователь с таким номером телефона существует!";
	}
    }

        if($data['email'] != $emuil) {
	// Проверка на уникальность email
    
	if(R::count('users', "email = ?", array($data['email'])) > 0) {

		$errors[] = "Пользователь с таким Email существует!";
	}
        }


	if(empty($errors)) {


        $id = $polzovatel;
        $user = R::load('users', $id);
                // добавляем в таблицу записи
		$user->telephone = $data['telephone'];
		$user->email = $data['email'];

		// Сохраняем таблицу
		R::store($user);
        echo '<div style="color: green; ">Успешно! Данные в профиле обновятся после переавторизации.</div><hr>';

	} else {
                // array_shift() извлекает первое значение массива array и возвращает его, сокращая размер array на один элемент. 
		echo '<div style="color: red; ">' . array_shift($errors). '</div><hr>';
	}
}

?>                                    
                                    
                                    
                                    
                                    
                                </div>
                                </div>
                            <!-- My Profile End -->
                            <!-- My Orders Start -->
                            <div class="tab-pane fade" id="v-pills-order" role="tabpanel" aria-labelledby="v-pills-order-tab">
                                <div class="card m-b-30">
                                    <div class="card-body">
                                        <div class="order-box">
                                            <div class="card border m-b-30">
                                                <div class="card-header">
                                                    <div class="row align-items-center">
 
<?php                                                       
$tss = R::getCell("SELECT SUM(price_zapisi) FROM zapisi WHERE telephone_zapisi = '".$pohon."'");
?>                                                     
                                                        
                                                        <div class="col-sm-6">
                                                            <h5>Общая стоимость всех услуг: <?php echo "$tss ₽"; ?></h5>
                                                        </div>
                                                    </div>
                                                </div>
                                                <div class="card-body">
                                                    <div class="table-responsive">
                                                        <table class="table table-borderless">
                                                            <thead>
                                                                <tr>
                                                                    <th scope="col">Асик</th>
                                                                    <th scope="col">Услуга</th>
                                                                    <th scope="col">Стоимость</th>
                                                                    <th scope="col">Статус</th>
                                                                    <th scope="col">Дата</th>
                                                                </tr>
                                                            </thead>
                                                            <tbody>
                                                                
<?php

$topUser = R::getAll("SELECT * FROM zapisi 
inner join services ON zapisi.services_id=services.id_services 
inner join asics ON zapisi.asic_id=asics.id_asic WHERE telephone_zapisi = '".$pohon."'");

                foreach ($topUser as $row) {
					echo "<tr>";
					echo "<td>" . $row['name_asic'] . "</td>";
                    echo "<td>" . $row['name_services'] . "</td>";
					echo "<td>" . $row['price_zapisi'] . " ₽</td>";
                    echo "<td>" . $row['status_zapisi'] . "</td>";
					echo "<td>" . $row['date_zapisi'] . "</td>";
					echo "</tr>";
                }
?>	                                                                
                                                            </tbody>
                                                        </table>
                                                    </div>
                                                </div>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                            </div>
                            <!-- My Orders End -->
                            <!-- My Orders Start -->
                            <div class="tab-pane fade" id="v-pills-wishlist" role="tabpanel" aria-labelledby="v-pills-wishlist-tab">
                                <div class="card m-b-30">
                                    <div class="card-body">
                                        <div class="order-box">
                                            <div class="card border m-b-30">
                                                <div class="card-header">
                                                    <div class="row align-items-center">
 
<?php                                                       
$tkk = R::getCell("SELECT SUM(price * count) FROM details WHERE client_id = '".$uebok."'");
?>                                                     
                                                        
                                                        <div class="col-sm-6">
                                                            <h5>Общая стоимость всех заказов: <?php echo "$tkk ₽"; ?></h5>
                                                        </div>
                                                    </div>
                                                </div>
                                                <div class="card-body">
                                                    <div class="table-responsive">
                                                        <table class="table table-borderless">
                                                            <thead>
                                                                <tr>
                                                                    <th scope="col">№</th>
                                                                    <th scope="col">Товар</th>
                                                                    <th scope="col">Стоимость</th>
                                                                    <th scope="col">Количество</th>
                                                                    <th scope="col">Статус</th>
                                                                    <th scope="col">Дата</th>
                                                                </tr>
                                                            </thead>
                                                            <tbody>
                                                                
<?php

$topUser2 = R::getAll("SELECT * FROM details WHERE client_id = '".$uebok."' ORDER BY date desc");

                foreach ($topUser2 as $row5) {
					echo "<tr>
					      <td>" . $row5['order_id'] . "</td>
                          <td>" . $row5['good'] . "</td>
				          <td>" . $row5['price'] . " ₽</td>
                          <td>" . $row5['count'] . "</td>
                          <td>" . $row5['status'] . "</td>
                          <td>" . $row5['date'] . "</td>
				          </tr>";
                }
?>	                                                                
                                                            </tbody>
                                                        </table>
                                                    </div>
                                                </div>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                            </div>
                            <!-- My Orders End -->
                            <!-- My Logout Start -->
                            <div class="tab-pane fade" id="v-pills-logout" role="tabpanel" aria-labelledby="v-pills-logout-tab">
                                <div class="card m-b-30">
                                    <div class="card-body">
                                        <div class="row justify-content-center">
                                            <div class="col-lg-6 col-xl-4">
                                                <div class="logout-content text-center my-5">
                                                    <img src="assets/images/ecommerce/logout.svg" class="img-fluid mb-5" alt="logout">
                                                    <h2 class="text-success">Выйти?</h2>
                                                    <p class="my-4">Вы уверены, что хотите выйти? (одумойся..)</p>
                                                    <div class="button-list">
                                                        <a href="logout.php" type="button" class="btn btn-success font-16"><i class="feather icon-check mr-2"></i>Да, я хочу выйти</a>
                                                    </div>
                                                </div>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                            </div>
                            <!-- My Logout End -->                            
                        </div>                        
                    </div>
                    <!-- End col -->
                </div>
                <!-- End row -->                  
            </div>
            <!-- End Contentbar -->
            <!-- Start Footerbar -->
            <div class="footerbar">
                <footer class="footer">
                    <p class="mb-0">© 2022 Асик - Все права защищены.</p>
                </footer>
            </div>
            <!-- End Footerbar -->
        </div>
        <!-- End Rightbar -->
    </div>
    <!-- End Containerbar -->
    <!-- End Containerbar -->
    <script src="index/assets/js/popper.min.js"></script>
    <script src="index/assets/js/bootstrap.min.js"></script>
    <script src="index/assets/js/modernizr.min.js"></script>
    <script src="index/assets/js/detect.js"></script>
    <script src="index/assets/js/jquery.slimscroll.js"></script>
    <script src="index/assets/js/vertical-menu.js"></script>
    <!-- Switchery js -->
    <script src="index/assets/plugins/switchery/switchery.min.js"></script>
    <!-- Apex js -->
    <!-- Slick js -->
    <script src="index/assets/plugins/slick/slick.min.js"></script>
    <!-- Custom Dashboard js -->   
    <script src="index/assets/js/custom/custom-dashboard.js"></script>
    <!-- Core js -->
    <script src="index/assets/js/core.js"></script>
    <!-- End js -->
</body>
</html>